//
//  OuterSearchViewController.m
//  Utils
//
//  Created by enghou on 2018/4/26.
//  Copyright © 2018年 xyxorigation. All rights reserved.
//

#import "OuterSearchViewController.h"
#import "NSMutableDictionary+SetContent.h"
@interface OuterSearchViewController ()
- (IBAction)birth_beginshow:(id)sender;
- (IBAction)birth_endshow:(id)sender;
- (IBAction)card_beginshow:(id)sender;
- (IBAction)card_endshow:(id)sender;
- (IBAction)arrival_beginshow:(id)sender;
- (IBAction)arrival_endshow:(id)sender;
- (IBAction)leave_beginshow:(id)sender;
- (IBAction)leave_endshow:(id)sender;


@property(nonatomic,strong)UIDatePicker *datePicker;
@end

@implementation OuterSearchViewController

-(NSMutableDictionary *)param{
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    [param setObject:self.foreignNamesField.text forKey:@"searchOverseaPersonnelVo.englishName"];
    [param setObject:self.chineseNameField.text forKey:@"searchOverseaPersonnelVo.name"];
    [param setObject:self.nowLocateDetailField.text forKey:@"searchOverseaPersonnelVo.currentAddress"];

    [param setContent:self.sexModel.ids forKey:@"searchOverseaPersonnelVo.gender" conentNeeded:NO];
    [param setContent:self.nationModel.ids forKey:@"searchOverseaPersonnelVo.nationality" conentNeeded:NO];
    [param setContent:self.proposeModel.ids forKey:@"searchOverseaPersonnelVo.inflowReason" conentNeeded:NO];
    [param setContent:self.proposeModel.ids forKey:@"searchOverseaPersonnelVo.professionId" conentNeeded:NO];
    [param setContent:self.search_birthBeginField.text forKey:@"searchOverseaPersonnelVo.birthdayStart" conentNeeded:NO];
    [param setContent:self.search_birthEndField.text forKey:@"searchOverseaPersonnelVo.birthdayEnd" conentNeeded:NO];
    [param setContent:self.search_cardBeginField.text forKey:@"searchOverseaPersonnelVo.certificateStrartDay" conentNeeded:NO];
    [param setContent:self.search_cardEndField.text forKey:@"searchOverseaPersonnelVo.certificateEndDay" conentNeeded:NO];
    [param setContent:self.search_arrivalBeginField.text forKey:@"searchOverseaPersonnelVo.arrivalTimeStart" conentNeeded:NO];
    [param setContent:self.search_arrivalEndField.text forKey:@"searchOverseaPersonnelVo.arrivalTimeEnd" conentNeeded:NO];
    [param setContent:self.search_leaveBeginField.text forKey:@"searchOverseaPersonnelVo.leaveTimeStart" conentNeeded:NO];
    [param setContent:self.search_leaveEndField.text forKey:@"searchOverseaPersonnelVo.leaveTimeEnd" conentNeeded:NO];
    return param;
}

-(void)query{
    NSDictionary *param = [self param];
    if ([self.theDelete respondsToSelector:@selector(fetchModel:)]) {
        [self.theDelete fetchModel:param];
        [self pop];
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"查询" style:UIBarButtonItemStylePlain target:self action:@selector(query)];
    self.navigationItem.rightBarButtonItem.tintColor = [UIColor whiteColor];
    
    self.datePicker = [[UIDatePicker alloc]initWithFrame:CGRectMake(0, 0, self.view.width, 240)];
    self.datePicker.locale = [NSLocale localeWithLocaleIdentifier:@"zh_CN"];
    self.datePicker.backgroundColor = [UIColor whiteColor];
    self.datePicker.datePickerMode = UIDatePickerModeDate;
    self.datePicker.minimumDate = [NSDate date];
    self.search_birthBeginField.inputView = self.datePicker;
    [self configInputField:self.search_birthBeginField];
    [self configInputField:self.search_birthEndField];
    [self configInputField:self.search_cardBeginField];
    [self configInputField:self.search_cardEndField];
    [self configInputField:self.search_arrivalBeginField];
    [self configInputField:self.search_arrivalEndField];
    [self configInputField:self.search_leaveBeginField];
    [self configInputField:self.search_leaveEndField];
}

-(void)configInputField:(UITextField *)field{
    field.inputView = self.datePicker;
    field.inputAccessoryView = [self inputAccessView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 3) {
        [self chooseSex];
    }else if (indexPath.row == 4){
        [self chooseNation];
    }else if (indexPath.row == 5){
        [self choosePopose];
    }else if (indexPath.row == 6){
        [self chooseOccupyCategory];
    }
}

-(void)sureAction{
    NSString *date = [[self.datePicker date]dateLineStrOnlyDay];
    for (UITextField *field in self.view.subviews) {
        if ([field isKindOfClass:[UITextField class]]) {
            if ([field isFirstResponder]) {
                field.text = date;
                break;
            }
        }
    }
    [self.view endEditing:YES];
}

-(void)cancelAction{
    [self.view endEditing:YES];
}

- (IBAction)birth_beginshow:(id)sender {
    [self.search_birthBeginField becomeFirstResponder];
}

- (IBAction)birth_endshow:(id)sender {
    [self.search_birthEndField becomeFirstResponder];
}

- (IBAction)card_beginshow:(id)sender {
    [self.search_cardBeginField becomeFirstResponder];
}

- (IBAction)card_endshow:(id)sender {
    [self.search_cardEndField becomeFirstResponder];
}

- (IBAction)arrival_beginshow:(id)sender {
    [self.search_arrivalBeginField becomeFirstResponder];
}

- (IBAction)arrival_endshow:(id)sender {
    [self.search_arrivalEndField becomeFirstResponder];
}

- (IBAction)leave_beginshow:(id)sender {
    [self.search_leaveBeginField becomeFirstResponder];
}

- (IBAction)leave_endshow:(id)sender {
    [self.search_leaveEndField becomeFirstResponder];
}
@end
